﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CarErp.Forms.Controls
{
	public partial class ListBar : UserControl
	{
		public ListBar()
		{
			InitializeComponent();
		}

		public void SetItems(int[] values)
		{
			Values = values;
			SelectedIndex = 0;	
		}

		private void button_First_Click(object sender, EventArgs e)
		{
			SelectedIndex = 0; ;
		}

		private void button_Pre_Click(object sender, EventArgs e)
		{
			SelectedIndex -= 1;
		}

		private void button_Next_Click(object sender, EventArgs e)
		{
			SelectedIndex += 1;
		}

		private void button_Last_Click(object sender, EventArgs e)
		{
			SelectedIndex = Values.Length - 1;
		}
		public int SelectedIndex
		{
			get { return _SelectedIndex; }
			private set
			{
				button_Pre.Enabled = value != 0;
				button_Next.Enabled = value != Values.Length - 1;

				_SelectedIndex = value;
				ItemSelected?.Invoke(Values[_SelectedIndex]);
			}
		}

		public int[] Values;
		private int _SelectedIndex;

		public event Action<int> ItemSelected;	
	}
}
